<template>
  <div>
    <div class="bgfff mtrbl20 ptrbl20 nopb20">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="管理企业" prop="companyAdminId">
            <el-select v-model="queryParams.companyAdminId" value-key="companyId" placeholder="请选择" clearable filterable size="medium" @change="change">
              <el-option
                v-for="dict in enterpriseDropDownOptions"
                :key="dict.companyId"
                :label="dict.companyName"
                :value="dict.companyId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="客户企业" prop="companyId" v-if="isShow">
            <el-select v-model="queryParams.companyId" placeholder="请选择" clearable size="medium" filterable>
              <el-option
                v-for="dict in clientCompany"
                :key="dict.companyId"
                :label="dict.companyName"
                :value="dict.companyId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="姓名" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入姓名"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="证件号" prop="idCard">
            <el-input
              v-model="queryParams.idCard"
              placeholder="请输入证件号"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="手机号" prop="userPhone">
            <el-input
              v-model="queryParams.userPhone"
              placeholder="请输入手机号"
              clearable
              size="medium"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="是否可用" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="全部"
              clearable
              size="medium"
            >
              <el-option label="否" value="0"></el-option>
              <el-option label="是" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        </el-col>
        </el-row>
      </div>
      <div class="app-container">  
        <el-row :gutter="20">
          <!--用户数据-->
          <el-col :span="24" :xs="24">
          <el-table v-loading="loading" :data="personnelList">
          
          <el-table-column label="序号" prop="" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="真实姓名" align="left" key="realName" prop="realName"/>
          <el-table-column label="用户姓名" align="left" key="userName" prop="userName"/>
          <el-table-column label="证件号" align="left" key="userIdNumber" prop="userIdNumber" width="150"/>
          <el-table-column label="手机号" align="left" key="userPhone" prop="userPhone" />
          <el-table-column label="性别" align="left" prop="userGender" :formatter="userGenderFormat"/>
          <el-table-column label="可用状态" align="left" prop="userStatus" :formatter="userStatusFormat"/>
          <el-table-column label="管理企业" align="left" key="companyAdminName" prop="companyAdminName" width="250"/>
          <el-table-column label="客户企业" align="left" key="companyName" prop="companyName" width="250"/>
          <el-table-column label="创建时间" align="left" key="userCreateTime" prop="userCreateTime" width="200"/>
          <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="small" type="text" icon="el-icon-view" v-hasPermi="['taxmsg:identity:listDetail']" @click="handleView(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

     <!-- 纳税人信息详情 -->
     <el-dialog title="人员信息详情" :visible.sync="openView" width="900px" append-to-body>
      <el-form ref="form" :model="form" label-width="150px" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名：">{{ form.userName }}</el-form-item>
            <el-form-item label="性别：">{{ userGenderFormat(form) }}</el-form-item>
            <el-form-item label="身份证号：">{{ form.userIdNumber }}</el-form-item>
            <el-form-item label="手机号：">{{ form.userPhone }}</el-form-item>
            <el-form-item label="电子邮箱：">{{ form.userEmail }}</el-form-item> 
          </el-col>
          <el-col :span="12">
            <el-form-item label="可用状态：">{{ userStatusFormat(form) }}</el-form-item>
            <el-form-item label="通讯地址：">{{ form.userAddress }}</el-form-item>
            <el-form-item label="管理企业：">{{ form.companyAdminName }}</el-form-item>
            <el-form-item label="客户企业：">{{ form.companyName }}</el-form-item>
            <el-form-item label="创建时间：">{{ form.userCreateTime }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openView = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
  </div>
</template>

<script>
import { personnelList, personnelListDetail } from "@/api/taxmsg/personnel";
export default {
  name: "Personnel",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      form: {},
      // 是否显示详细弹出层
      openView: false,
      // 用户表格数据
      personnelList: null,
       // 所有的管理企业和关联客户企业信息数据字典
      enterpriseDropDownOptions: [],
      clientCompany:[],
      isShow:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        companyAdminId: undefined,
        companyId: undefined,
        userName: undefined,
        idCard: undefined,
        userPhone: undefined,
        status: undefined
      }
    };
  },
  created() {
    this.getList();
    this.getEnterpriseDropDown().then(response => {
      this.enterpriseDropDownOptions = response.data;
    });
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      personnelList(this.queryParams).then(response => {
          this.personnelList = response.data.tableData;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    change(e){
      delete this.queryParams.companyId
      if(e){
        this.isShow = true;
        this.clientCompany = this.enterpriseDropDownOptions.filter(item => item.companyId === e)[0].clientCompany;
      }else{
        this.isShow = false
      }
    },
    // 性别状态翻译
    userGenderFormat(row) {
      let userGender = row.userGender;
      switch (userGender) {
        case '0':
        userGender = "未知";
          break;
        case '1':
        userGender = "男";
          break;
        case '2':
        userGender = "女";
          break;
      }
      return userGender;
    },
    // 状态字典翻译
    userStatusFormat(row, column) {
      let status = row.userStatus;
      switch (status) {
        case '0':
        status = "否";
          break;
        case '1':
        status = "是";
          break;
      }
      return status;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
      this.isShow = false;
    },
    /** 人员信息详情 */
    handleView(row) {
      personnelListDetail(row.userId).then(response => {
        this.form = response.data.identityBase;
        this.openView = true;
      });
    },
  }
};
</script>
<style scoped lang="scss">
</style>